home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / sav_to_gbs.s < prev    next >
Text File  |  1999-04-15  |  12KB  |  453 lines

  1.  
  2. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  3. ;        .sav to .gbs converter
  4. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  5.  
  6.         incdir    "binworld:includes/"
  7.         include    "exec/memory.i"
  8.         include    "dos/dos.i"
  9.         include    "exec_lib.i"
  10.         include    "dos_lib.i"
  11.  
  12. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  13. ;        section    juures,code
  14. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  15.  
  16. sav_to_gbs:    movem.l    d2-d7/a2-a6,-(SP)        ;stack!
  17.         move.l    execbase,exec_base        ;cache it locally.
  18.  
  19.         move.l    a0,cli_input            ;store the pointer.
  20.  
  21.         move.l    exec_base,a6
  22.         lea    dos_name,a1
  23.         moveq.l    #39,d0
  24.         jsr    OpenLibrary(a6)
  25.         move.l    d0,dos_base
  26.         beq.w    quit
  27.  
  28. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  29. ;        allocate some memory
  30. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  31.  
  32.         move.l    exec_base,a6
  33.         move.l    #256,d0
  34.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;the system flags.
  35.         jsr    AllocVec(a6)
  36.         move.l    d0,name_input            ;the pointer here.
  37.         beq.w    quit
  38.  
  39.         move.l    #256,d0
  40.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;the system flags.
  41.         jsr    AllocVec(a6)
  42.         move.l    d0,name_output            ;the pointer here.
  43.         beq.w    quit
  44.  
  45.         move.l    #256,d0
  46.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;the system flags.
  47.         jsr    AllocVec(a6)
  48.         move.l    d0,file_info_ptr        ;the pointer here.
  49.         beq.w    quit
  50.  
  51.         move.l    #$10000,d0
  52.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;the system flags.
  53.         jsr    AllocVec(a6)
  54.         move.l    d0,cartridge_ram        ;the pointer here.
  55.         beq.w    quit
  56.  
  57. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  58. ;        empty input?
  59. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  60.  
  61.         move.l    cli_input,a0
  62.         cmp.b    #$A,(a0)
  63.         beq.w    show_syntax
  64.  
  65. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  66. ;        read input and output names
  67. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  68.  
  69.         move.l    cli_input,a0
  70.         move.l    name_input,a1
  71.         bsr.b    get_name
  72.         tst.l    d0
  73.         bne.w    quit
  74.  
  75.         subq.l    #1,a0                ;back one step.
  76.         move.l    name_output,a1
  77.         bsr.b    get_name
  78.         tst.l    d0
  79.         bne.w    quit
  80.  
  81.         bra.w    load_data
  82.  
  83. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  84. ;        get name
  85. ;        INPUT:
  86. ;        a0    = input.
  87. ;        a1    = output.
  88. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  89.  
  90. get_name:    move.w    #256-1,d0
  91. get_name_start:    move.b    (a0)+,d1
  92.         beq.s    get_name_error
  93.         cmp.b    #" ",d1
  94.         bne.s    get_name_get
  95.         dbra    d0,get_name_start
  96.         bra.s    get_name_error
  97.  
  98. get_name_get:    move.b    d1,(a1)+
  99. get_name_data:    move.b    (a0)+,d1
  100.         beq.s    get_name_end
  101.         cmp.b    #" ",d1
  102.         beq.s    get_name_end
  103.         cmp.b    #$A,d1
  104.         beq.s    get_name_end
  105.         move.b    d1,(a1)+
  106.         dbra    d0,get_name_data
  107.         bra.s    get_name_error
  108.  
  109. get_name_end:    clr.b    (a1)
  110.         moveq.l    #0,d0                ;no errors.
  111.         rts
  112.  
  113. get_name_error:    moveq.l    #1,d0                ;error!
  114.         rts
  115.  
  116. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  117. ;        find out if the file can be unpacked with xpk master
  118. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  119.  
  120. load_data:    move.l    dos_base,a6
  121.         move.l    name_input,d1            ;the name.
  122.         moveq.l    #ACCESS_READ,d2
  123.         jsr    Lock(a6)
  124.         move.l    d0,file_hd
  125.         beq.w    error_in_open            ;en error occurred!
  126.  
  127.         move.l    file_info_ptr,d2
  128.         move.l    file_hd,d1
  129.         jsr    Examine(a6)            ;load file info.
  130.  
  131.         move.l    file_hd,d1
  132.         jsr    UnLock(a6)            ;unlock it.
  133.  
  134. take_the_length:move.l    file_info_ptr,a0
  135.         move.l    124(a0),file_length        ;store the length.
  136.  
  137. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  138. ;        check the file size
  139. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  140.  
  141.         cmp.l    #8192,file_length
  142.         beq.s    l_is_ok
  143.         cmp.l    #8192*4,file_length
  144.         bne.w    error_in_size
  145. l_is_ok:    
  146.  
  147. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  148. ;        cartridge loader memory handler
  149. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  150.  
  151.         move.l    exec_base,a6
  152.         move.l    file_length,d0
  153.         moveq.l    #MEMF_PUBLIC,d1            ;the system flags.
  154.         jsr    AllocVec(a6)
  155.         move.l    d0,cartridge            ;the pointer here.
  156.         beq.w    quit                ;not enough memory! quit.
  157.  
  158. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  159. ;        now load the file
  160. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  161.  
  162.         move.l    dos_base,a6            ;open the data file.
  163.         move.l    name_input,d1            ;the name of the file.
  164.         move.l    #Mode_Old,d2
  165.         jsr    Open(a6)            ;narsk.
  166.         move.l    d0,file_hd
  167.         beq.w    quit                ;file error!
  168.  
  169.         move.l    d0,d1                ;file_hd.
  170.         move.l    cartridge,d2            ;output address.
  171.         move.l    file_length,d3            ;the length.
  172.         jsr    Read(a6)            ;read.
  173.  
  174.         move.l    file_hd,d1
  175.         jsr    Close(a6)            ;click.
  176.  
  177. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  178. ;        prepare the values
  179. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  180.  
  181.         move.l    cartridge_ram,a0
  182.         clr.l    (a0)+                ;z80_halt.B, 3x.B 0.
  183.         move.l    #$00D80013,(a0)+        ;bcde.
  184.         move.l    #$100,(a0)+            ;pc.
  185.         move.l    #$0000014D,(a0)+        ;hl.
  186.         move.l    #$0000B001,(a0)+        ;fa.
  187.         clr.l    (a0)+                ;ccr.
  188.         move.l    #$0000FFFE,(a0)+        ;sp.
  189.  
  190.         clr.l    (a0)+                ;compability.
  191.         clr.l    (a0)+
  192.         clr.l    (a0)+
  193.         clr.l    (a0)+
  194.  
  195.         move.l    #453/5,(a0)+            ;z80_cycles.
  196.         clr.l    (a0)+                ;bank_address-rom_32k.
  197.         clr.l    (a0)                ;ram_bank_no.
  198.  
  199. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  200. ;        now save the RAM banks as a .gbs file
  201. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  202.  
  203.         move.l    dos_base,a6            ;open the data file.
  204.         move.l    name_output,d1            ;the name of the file.
  205.         move.l    #Mode_New,d2
  206.         jsr    Open(a6)            ;narsk.
  207.         move.l    d0,file_hd
  208.         beq.w    error_in_save            ;file error!
  209.  
  210.         move.l    d0,d1                ;file_hd.
  211.         move.l    cartridge_ram,d2        ;input address.
  212.         moveq.l    #56,d3                ;the length.
  213.         jsr    Write(a6)            ;write.
  214.  
  215. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  216. ;        now save out the RAM
  217. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  218.  
  219.         move.l    file_hd,d1
  220.         move.l    cartridge_ram,d2
  221.         add.l    #56,d2
  222.         move.l    #$A000-$8000,d3            ;video ram.
  223.         jsr    Write(a6)
  224.  
  225.         move.l    file_hd,d1
  226.         move.l    cartridge,d2
  227.         move.l    #$2000,d3            ;ram bank 0.
  228.         jsr    Write(a6)
  229.  
  230.         move.l    file_hd,d1
  231.         move.l    cartridge_ram,d2
  232.         add.l    #56,d2
  233.         move.l    #$FF00-$C000,d3            ;upper ram.
  234.         jsr    Write(a6)
  235.  
  236.         move.l    cartridge_ram,a0
  237.         add.l    #56,a0
  238.         move.l    a0,a1
  239.         addq.l    #7,a1
  240.         move.b    #$F8,(a1)            ;TIMCONT = $f8!
  241.         subq.l    #1,a1
  242.         move.b    #1,(a1)                ;TIMEMOD = 1.
  243.         subq.l    #1,a1
  244.         move.b    #1,(a1)                ;TIMECNT = 1.
  245.         move.l    a0,a2
  246.         add.l    #$40,a2                ;a2 = LCDCONT.
  247.         move.b    #$81,(a2)
  248.         addq.l    #1,a2                ;a2 = LCDSTAT.
  249.         clr.b    (a2)
  250.         addq.l    #4,a2                ;a2 = CMPLINE.
  251.         move.b    #$ff,(a2)
  252.  
  253.         move.b    #%11111111,(a0)            ;reset the buttons.
  254.  
  255.         move.l    file_hd,d1
  256.         move.l    cartridge_ram,d2
  257.         add.l    #56,d2
  258.         move.l    #$10000-$FF00,d3        ;upmost ram.
  259.         jsr    Write(a6)
  260.  
  261. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  262. ;        now many banks must be saved?
  263. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  264.  
  265.         move.l    cartridge_ram,a0
  266.         add.l    #56,a0
  267.  
  268.         cmp.l    #8192,file_length
  269.         beq.s    l_8192
  270.  
  271. l_32768:    move.l    #4,(a0)                ;four banks.
  272.         
  273.         move.l    file_hd,d1
  274.         move.l    cartridge_ram,d2
  275.         add.l    #56,d2
  276.         moveq.l    #4,d3                ;misc bytes.
  277.         jsr    Write(a6)
  278.  
  279.         move.l    file_hd,d1
  280.         move.l    cartridge,d2
  281.         move.l    #$2000*4,d3            ;the four ram banks.
  282.         jsr    Write(a6)
  283.  
  284.         move.l    cartridge_ram,a0
  285.         add.l    #56,a0
  286.         clr.b    (a0)                ;i_flag.
  287.  
  288.         move.l    file_hd,d1
  289.         move.l    cartridge_ram,d2
  290.         add.l    #56,d2
  291.         moveq.l    #1,d3                ;i_flag.
  292.         jsr    Write(a6)
  293.  
  294.         bra.s    exit_save
  295.  
  296. l_8192:        clr.l    (a0)+                ;no banks saved.
  297.         clr.b    (a0)                ;i_flag.
  298.  
  299.         move.l    file_hd,d1
  300.         move.l    cartridge_ram,d2
  301.         add.l    #56,d2
  302.         moveq.l    #5,d3                ;misc bytes.
  303.         jsr    Write(a6)
  304.  
  305. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  306. ;        close the output
  307. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  308.  
  309. exit_save:    move.l    file_hd,d1
  310.         jsr    Close(a6)            ;click.
  311.  
  312.         bsr.w    get_output
  313.         move.l    #ok_message,d2
  314.         move.l    #ok_message_end-ok_message,d3
  315.         bsr.w    print_message
  316.  
  317. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  318. ;        quit / exit
  319. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  320.  
  321. quit:        move.l    exec_base,a6
  322.  
  323.         move.l    cartridge,d0
  324.         bsr.b    free_vec_sub
  325.         move.l    name_input,d0
  326.         bsr.b    free_vec_sub
  327.         move.l    name_output,d0
  328.         bsr.b    free_vec_sub
  329.         move.l    cartridge_ram,d0
  330.         bsr.b    free_vec_sub
  331.         move.l    file_info_ptr,d0
  332.         bsr.b    free_vec_sub
  333.  
  334.         move.l    dos_base,d0
  335.         move.l    d0,a1
  336.         beq.s    no_free_dos
  337.         jsr    CloseLibrary(a6)
  338.  
  339. no_free_dos:    movem.l    (SP)+,d2-d7/a2-a6        ;unstack!
  340.         moveq.l    #0,d0                ;no errors.
  341.         rts
  342.  
  343. free_vec_sub:    move.l    d0,a1
  344.         beq.s    no_vec                ;no vector.
  345.         jsr    FreeVec(a6)            ;free the area.
  346. no_vec:        rts
  347.  
  348. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  349. ;        (error) messages
  350. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  351.  
  352. error_in_open:    bsr.b    get_output
  353.         move.l    #e_open_msg,d2
  354.         move.l    #e_open_msg_end-e_open_msg,d3
  355.         bsr.b    print_message
  356.         bra.b    quit
  357.  
  358. error_in_save:    bsr.b    get_output
  359.         move.l    #e_save_msg,d2
  360.         move.l    #e_save_msg_end-e_save_msg,d3
  361.         bsr.b    print_message
  362.         bra.b    quit
  363.  
  364. error_in_size:    bsr.b    get_output
  365.         move.l    #e_size_msg,d2
  366.         move.l    #e_size_msg_end-e_size_msg,d3
  367.         bsr.b    print_message
  368.         bra.w    quit
  369.  
  370. show_syntax:    bsr.b    get_output
  371.         move.l    #syntax_msg,d2
  372.         move.l    #syntax_msg_end-syntax_msg,d3
  373.         bsr.b    print_message
  374.         bra.w    quit
  375.  
  376. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  377. ;        get the output pointer / print an message
  378. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  379.  
  380. get_output:    move.l    dos_base,a6
  381.         jsr    Output(a6)
  382.         rts
  383.  
  384. print_message:    move.l    d0,d1
  385.         jsr    Write(a6)
  386.         rts
  387.  
  388. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  389. ;        section    murrr,data
  390. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  391.  
  392. dos_name:    dc.b    "dos.library",0
  393.         even
  394.  
  395. exec_base:    dc.l    0
  396. dos_base:    dc.l    0
  397.  
  398. cli_input:    dc.l    0
  399.  
  400. file_length:    dc.l    0
  401. file_hd:    dc.l    0
  402.  
  403. name_input:    dc.l    0
  404. name_output:    dc.l    0
  405.  
  406. cartridge:    dc.l    0
  407. cartridge_ram:    dc.l    0
  408. file_info_ptr:    dc.l    0
  409.  
  410. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  411. ;        the syntax message
  412. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  413.  
  414. syntax_msg:    dc.b    $A
  415.         dc.b    "      VGB .sav to Wzonka-Lad .gbs file converter v1.0",$A
  416.         dc.b    "          Copyright 1997 Ville Helin (01-Jun-97)     ",$A,$A
  417.         dc.b    "SYNTAX: sav_to_gbs [INPUT NAME (.SAV)] [OUTPUT NAME (.GBS)]",$A,$A
  418.         dc.b    0
  419. syntax_msg_end:    even
  420.  
  421. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  422. ;        error messages
  423. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  424.  
  425. e_save_msg:    dc.b    "Error in output.",$A
  426.         dc.b    0
  427. e_save_msg_end:    even
  428.  
  429. e_open_msg:    dc.b    "Error in input.",$A
  430.         dc.b    0
  431. e_open_msg_end:    even
  432.  
  433. e_size_msg:    dc.b    "Error in size. Must be 8192/32768 bytes.",$A
  434.         dc.b    0
  435. e_size_msg_end:    even
  436.  
  437. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  438. ;        no conversion errors message
  439. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  440.  
  441. ok_message:    dc.b    "No errors.",$A
  442.         dc.b    0
  443. ok_message_end:    even
  444.  
  445. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  446. ;        version string
  447. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  448.  
  449. snapshot_to_sav:dc.b    "$VER: .sav to .gbs converter 1.0 (01.06.97)",0
  450.         even
  451.  
  452.         END
  453.